package gold.digger;

import gold.vo.TreeNode;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC889 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        int[] pre, post;

        public TreeNode constructFromPrePost(int[] pre, int[] post) {
            this.pre = pre;
            this.post = post;
            return make(0, 0, pre.length);
        }

        public TreeNode make(int i0, int i1, int N) {
            if (N == 0) return null;
            TreeNode root = new TreeNode(pre[i0]);
            if (N == 1) return root;

            int L = 1;
            for (; L < N; ++L)
                if (post[i1 + L - 1] == pre[i0 + 1])
                    break;

            root.left = make(i0 + 1, i1, L);
            root.right = make(i0 + L + 1, i1 + L, N - 1 - L);
            return root;
        }
    }


    public void run() {
        Solution solution = new Solution();
        List<Integer> list = new ArrayList<>();
        System.out.println(solution.toString());
    }

    public static void main(String[] args) throws Exception {
        LC889 an = new LC889();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
